#include <iostream>
#include <string>

class Student
{
public:
    Student() // 无参构造函数:默认构造函数
    {
        std::cout << "无参构造" << std::endl;
    }
    // 有参构造
    Student(int id, const char *name) // 构造函数允许重载
    {
        std::cout << "有参构造" << std::endl;
        m_id = id;
        m_name = name;
    }

    // 拷贝构造函数
    Student(const Student &s) // 不带引用会导致无限复制
    {
        std::cout << "拷贝构造函数\n";
        m_id = s.m_id;
        m_name = s.m_name;
    }

    //赋值运算符的重载
    void operator = (const Student &s)
    {
        std::cout<<"赋值运算符重载\n";
        m_id = s.m_id;
        m_name = s.m_name;
    }
    void Print()
    {
        std::cout << m_id << " " << m_name << std::endl;
    }

    ~Student()
    {
        std::cout<<"析构函数"<<std::endl;
    }

private:
    int m_id;
    std::string m_name;
};

int main()
{
    Student s1(1,"zhangsan");//有参构造
    Student s2(s1); //拷贝构造
    Student s3;
    s3 = s1;
    s3.Print();
    return 0;
}